import React, { Component } from 'react';
import { connect } from 'dva';
import { message, Modal, Pagination, Popconfirm, Button } from 'antd';
import styles from './../Users.css';
import moment from 'moment';
import Factory from '../../factory';
import numeral from 'numeral';
import * as datetime from '../../../utils/datetime'
import dataEditCreate from '../../addons/DataEdit'
import dataTableCreate from '../../addons/DataTable'
import * as menuService from '../../../services/menus';
import * as common from '../../../utils/common';

const daoName = "CM_INDV_CUST_DIM";
const ButtonGroup = Button.Group;      
const renderNumber = (num) => {
  let value = ''
  if (num) {
    value = numeral(num).format('0,0')
  }
  return value
};
const columns = [
  { title: '客户名称', width: 120, sorter: true, dataIndex: 'KHMC', key: 'KHMC', dispaly: true, filter: true },
  { title: '证件类型', width: 120, sorter: true, key: 'ZJLX', dataIndex: "ZJLX", dispaly: true, filter: true },
  { title: '证件号码', width: 170, sorter: true, dataIndex: 'ZHHM', key: 'ZHHM', dispaly: true, filter: true },
  { title: '性别', width: 100, sorter: true, dataIndex: 'SEX', key: 'SEX', dispaly: true, filter: true },
  { title: '出生日期', width: 120, sorter: true, caption: 'CSRQ', key: 'CSRQ', dispaly: true, filter: true, render: data => datetime.format(data.CSRQ, "yyyy-MM-dd") },
  { title: '所属机构', width: 190, sorter: true, dataIndex: 'SSJG', key: 'SSJG', dispaly: true, filter: true },
  { title: '贷款授信额度', width: 155, sorter: true, dataIndex: 'DKSX', key: 'DKSX', dispaly: true, filter: true },
  { title: '信用卡授信额度', width: 160, sorter: true, dataIndex: 'XYKSX', key: 'XYKSX', dispaly: true, filter: true },
  { title: '是否代发工资客户', width: 165, sorter: true, dataIndex: 'DFGZ', key: 'DFGZ', dispaly: true, filter: true },
  { title: '是否个贷客户', width: 160, sorter: true, dataIndex: 'GD', key: 'GD', dispaly: true, filter: true },
  { title: '是否手机银行客户', width: 165, sorter: true, dataIndex: 'SJYH', key: 'SJYH', dispaly: true, filter: true },
  { title: '是否信用卡客户', width: 160, sorter: true, dataIndex: 'XYK', key: 'XYK', dispaly: true, filter: true },
  { title: '客户经理1', width: 100, sorter: false, dataIndex: 'YG1', key: 'YG1', dispaly: true, filter: false },
  { title: '分配比例1(%)', width: 100, sorter: false, className: "column-money", caption: 'ZB1', render: data => renderNumber(data.ZB1), key: 'ZB1', dispaly: true, filter: false },
  { title: '客户经理2', width: 100, sorter: false, dataIndex: 'YG2', key: 'YG2', dispaly: true, filter: false },
  { title: '分配比例2(%)', width: 100, sorter: false, className: "column-money", caption: 'ZB2', render: data => renderNumber(data.ZB2), key: 'ZB2', dispaly: true, filter: false },
  { title: '客户经理3', width: 100, sorter: false, dataIndex: 'YG3', key: 'YG3', dispaly: true, filter: false },
  { title: '分配比例3(%)', width: 100, sorter: false, className: "column-money", caption: 'ZB3', render: data => renderNumber(data.ZB3), key: 'ZB3', dispaly: true, filter: false },
  { title: '客户经理4', width: 100, sorter: false, dataIndex: 'YG4', key: 'YG4', dispaly: true, filter: false },
  { title: '分配比例4(%)', width: 100, sorter: false, className: "column-money", caption: 'ZB4', render: data => renderNumber(data.ZB4), key: 'ZB4', dispaly: true, filter: false },
  { title: '客户经理5', width: 100, sorter: false, dataIndex: 'YG5', key: 'YG5', dispaly: true, filter: false },
  { title: '分配比例5(%)', width: 100, sorter: false, className: "column-money", caption: 'ZB5', render: data => renderNumber(data.ZB5), key: 'ZB5', dispaly: true, filter: false },
];
const controls = [
  { name: 'KHMC', required: true, type: 'text', label: '客户名称', grid: 12 / 24 },
  { name: 'ZJLX', required: true, type: 'text', label: '证件类型', grid: 12 / 24 },
  { name: 'ZHHM', required: true, type: 'text', label: '证件号码', grid: 12 / 24 },
  { name: 'SEX', required: true, type: 'text', label: '性别', grid: 12 / 24 },
  { name: 'CSRQ', required: true, type: 'date', label: '出生日期', grid: 12 / 24, dataType: 'date' },
  { name: 'SSJG', required: true, type: 'text', label: '所属机构', grid: 12 / 24 },
  { name: 'DKSX', required: true, type: 'number', label: '贷款授信额度', grid: 12 / 24 },
  { name: 'XYKSX', required: true, type: 'number', label: '信用卡授信额度', grid: 12 / 24 },
  { name: 'DFGZ', required: true, type: 'text', label: '是否代发工资客户', grid: 12 / 24 },
  { name: 'GD', required: true, type: 'text', label: '是否个贷客户', grid: 12 / 24 },
  { name: 'SJYH', required: true, type: 'text', label: '是否手机银行客户', grid: 12 / 24 },
  { name: 'XYK', required: true, type: 'text', label: '是否信用卡客户', grid: 12 / 24 },
];
const EditFrom = dataEditCreate(daoName);
const DataTable = dataTableCreate(daoName);
/*对私客户信息 */
class CM_INDV_CUST_DIMForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      dataChange: false
    };
  }
  componentDidMount() {
    this.props.dispatch({
      type: `${daoName}/setKeyName`,
      payload: { keyName: "ID", permID: this.props.permID }
    });
    this.props.dispatch({
      type: `${daoName}/fetch`,
      payload: { daoName, page: 1, pageSize: 20 }
    });
    this.loadOptionData();
  }
  loadOptionData() {
    let options = []
    controls.map(c => {
      if (c.fetch) {
        let f = c.fetch;
        if (c.type === 'cascader-select') {
          f.isCascader = true;
        }
        if (c.type !== 'search') {
          options.push(f);
        }
      }
    })
    if (daoName && options.length > 0) {
      this.props.dispatch({ type: `${daoName}/fetchOptions`, payload: { options } });
    }
  }
  render() {
    let { showEdit, record, permID } = this.props;
    return (
      <div className={styles.normal} style={{ background: '#fff', marginTop: -16, padding: '5px 5px' }}>
        <div>
          <div className={styles.create}>
          </div>
          <DataTable ref="userTable" daoName={daoName} columns={columns} controls={controls} permID={permID} />
        </div>
      </div>
    )
  }
}
function mapStateToProps(state) {
  const { showEdit, record, selectedRowKeys, keyName } = state[daoName];
  return {
    showEdit,
    selectedRowKeys,
    keyName,
    record
  }
}
CM_INDV_CUST_DIMForm = connect(mapStateToProps)(CM_INDV_CUST_DIMForm)
export default CM_INDV_CUST_DIMForm;
let render = (props) => React.createElement(CM_INDV_CUST_DIMForm, props);
let f = new Factory()
f.set("CM_INDV_CUST_DIMForm", render)